<!--密码重置-->
<div class="setPsd" ng-controller="setUserPsd">
    <form class="form-horizontal"  name="reSetForm" ng-submit="processReSetForm(reSetForm.$valid)" novalidate>
        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-2">
                <small class="text-danger hide" id="errorInfo">信息不匹配，请稍后重试</small>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">原密码</label>
            <div class="col-sm-4">
                <input type="password" class="form-control" name="oldPassword" ng-model="reSetFormData.oldPassword" ng-minlength="6" ng-maxlength="12" ng-pattern="/^[x00-x7f]+$/" placeholder="请输入原密码" required />
                <label for="inputError" class="control-label text-danger" ng-show="reSetForm.oldPassword.$invalid && !reSetForm.oldPassword.$pristine"><i class="fa fa-times-circle-o"></i> 密码格式不正确</label>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">新密码</label>
            <div class="col-sm-4">
                <input type="password" class="form-control" name="password" id="userPassword" ng-model="reSetFormData.password" ng-minlength="6" ng-maxlength="12" ng-pattern="/^[x00-x7f]+$/" placeholder="请输入新密码" required/>
                <label for="inputError" class="control-label text-danger"  ng-show="reSetForm.password.$invalid && !reSetForm.password.$pristine"><i class="fa fa-times-circle-o"></i> 密码格式不正确</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">确认密码</label>
            <div class="col-sm-4">
                <input type="password" class="form-control" pw-check="userPassword" name="confirmPassword" ng-model="reSetFormData.confirmPassword" placeholder="请再次输入密码" ng-minlength="6" ng-maxlength="12" ng-pattern="/^[x00-x7f]+$/" required/>
                <label for="inputError" class="control-label text-danger" ng-show="reSetForm.confirmPassword.$invalid && !reSetForm.confirmPassword.$pristine"><i class="fa fa-times-circle-o"></i> 两次输入密码不一直</label>

            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-default" ng-disabled="reSetForm.$invalid">提交</button>
            </div>
        </div>
    </form>
</div>


<script>
    doraApp.controller("setUserPsd",function($scope,$http) {
        //        重置密码
        $scope.processReSetForm = function(isValid){

            if (isValid) {

                var uid = '<%= userInfo._id%>';
                $http({
                    method: 'POST',
                    url: "/users/resetMyPsd?uid="+uid,
                    data: $.param($scope.reSetFormData),  // pass in data as strings
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }  // set the headers so angular passing info as form data (not request payload)
                })
                .success(function (data) {
                    if (data === "success") {
                        alert('密码修改成功！为安全起见，请退出后重新登录');
                        window.location.reload();
                    } else {
                        $('#errorInfo').removeClass('hide');
                    }
                });
            }
        };
    })
</script>